package com.example.compose;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;



class Y123{
    private String title;
    private int res;

    public Y123(String title, int res) {
        this.title = title;
        this.res = res;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public int getRes() {
        return res;
    }
    public void setRes(int res) {
        this.res = res;
    }
}



@SuppressLint("CustomViewStyleable")
public class RoundedCornersTextView extends androidx.appcompat.widget.AppCompatTextView {

    private float corners = -1;
    private List<Y123> data = Arrays.asList(new Y123("标题一",R.mipmap.bg),new Y123("标题二",R.mipmap.bg),new Y123("标题三",R.mipmap.bg));


    public RoundedCornersTextView(Context context) {
        super(context);
    }

    public RoundedCornersTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RoundedCornersTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }

    public void setCorners(int rx){
        corners = rx;
    }

    @Override
    public void setBackgroundColor(int color) {
        setBackground(new Drawable() {
            @Override
            public void draw(@NonNull Canvas canvas) {
                if(corners==-1) {corners=getHeight()/6f;}
                Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                paint.setColor(color);
                canvas.drawRoundRect(new RectF(0,0,getWidth(),getHeight()),corners,corners,paint);
            }

            @Override
            public void setAlpha(int alpha) {

            }

            @Override
            public void setColorFilter(@Nullable ColorFilter colorFilter) {

            }

            @Override
            public int getOpacity() {
                return PixelFormat.UNKNOWN;
            }
        });
    }

}
